package com.fulu.jvm.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Util {

    public static void main(String[] args) {
        boolean exit = false;
        while (!exit) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("Enter hex string:");
            final String ascii = scanner.nextLine();
            if("exit".equals(ascii)){
                exit = true;
                break;
            }
            System.out.println(asciiToString(ascii));
        }
    }

    public static String asciiToString(String ascii){
        ascii = ascii.replace(" ", "");
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < ascii.length(); i+=2) {
            String substring = ascii.substring(i, i + 2);
            final int anInt = Integer.parseInt(substring, 16);
            builder.append(Character.toChars(anInt));
        }
        return builder.toString();
    }
}
